package org.gcu.filestorage.controller;

import lombok.extern.slf4j.Slf4j;
import org.gcu.filestorage.api.ErrorCode;
import org.gcu.filestorage.pojo.RequestResult;
import org.gcu.filestorage.pojo.SpaceStatus;
import org.gcu.filestorage.serive.ApplyInfoService;
import org.gcu.filestorage.uitls.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class SpaceController {

    private final ApplyInfoService applyInfoService;

    @Autowired
    public SpaceController(ApplyInfoService applyInfoService) {
        this.applyInfoService = applyInfoService;
    }

    @PostMapping("/querySpaceStatus")
    public RequestResult<SpaceStatus> querySpaceStatus(@RequestHeader("Authorization") String token) {
        log.info("querySpaceStatus(), token=" + token);
        RequestResult<SpaceStatus> requestResult = new RequestResult<>();
        String account = TokenUtil.parseAccount(token);
        SpaceStatus spaceStatus = applyInfoService.querySpaceInfo(account);
        requestResult.setResCode(ErrorCode.SUCCESS);
        requestResult.setData(spaceStatus);
        requestResult.setMessage("查询成功");
        return requestResult;
    }
}
